import Vue from 'vue'
import Router from 'vue-router'
/*import home from 'components/home/home.vue'
import list from 'components/list/list.vue'*/

const home = resolve => require(['components/home/home.vue'], resolve)
const about = resolve => require(['components/about/about.vue'], resolve)
const business = resolve => require(['components/business/business.vue'], resolve)
const duty = resolve => require(['components/duty/duty.vue'], resolve)
// const list = resolve => require(['components/list/list.vue'], resolve)

Vue.use(Router)

//初始表现
const scrollBehavior = (to, from, savedPosition) => {
  if (savedPosition) {
    // savedPosition is only available for popstate navigations.
    return savedPosition
  } else {
    const position = {}
    // new navigation.
    // scroll to anchor by returning the selector
    if (to.hash) {
      position.selector = to.hash
    }
    // check if any matched route config has meta that requires scrolling to top
    if (to.matched.some(m => m.meta.scrollToTop)) {
      // cords will be used if no selector is provided,
      // or if the selector didn't match any element.
      position.x = 0
      position.y = 0
    }
    // if the returned position is falsy or an empty object,
    // will retain current scroll position.
    return position
  }
}

export default new Router({
  scrollBehavior,
  routes: [
    {
      path: '/',
      name: 'home',
      component: home
    },
    {
      path: '/about/:type',
      name: 'about',
      component: about
    },
    {
      path: '/business',
      name: 'business',
      component: business
    },
    {
      path: '/duty/:type',
      name: 'duty',
      component: duty
    }
  ]
})
